﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

using Factonomy.AzureUtility.Core;
using Factonomy.AzureUtility.Core.Storage;
using Factonomy.AzureUtility.Core.StorageHelpers;

namespace Factonomy.AzureUtility.Controls
{
    /// <summary>
    /// Interaction logic for InfoPanel.xaml
    /// </summary>
    public partial class InfoPanel : UserControl
    {
        public enum InfoPanelType
        {
            Application,
            Account,
            Container,
            Blob
        }

        public InfoPanel()
        {
            InitializeComponent();
        }

        public void Show(TreeViewItemHelper helper)
        {
            if (helper.NodeType == TreeViewItemHelper.NodeTypeEnum.Account)
            {
                this.uiAccountHeader.Text = helper.AccountName;
                this.uiAccountSub.Text = BlobHelper.Instance.GetBaseUri(Config.Instance.GetAccount(helper.AccountName)).ToString();
                this.Show(InfoPanelType.Account);
            }
            else if(helper.NodeType == TreeViewItemHelper.NodeTypeEnum.Container)
            {
                this.uiContainerHeader.Text = helper.Container;
                BlobContainer container = BlobHelper.Instance.GetContainer(Config.Instance.GetAccount(helper.AccountName), helper.Container);
                this.uiContainerSub.Text = container.ContainerUri.ToString();
                this.Show(InfoPanelType.Container);
            }
        }

        public void Show(BlobContainer container, BlobProperties properties)
        {
            this.uiBlobHeader.Text = properties.Name;
            this.uiBlobSub.Text = properties.Uri.ToString();
            this.Show(InfoPanelType.Blob);
        }

        private void Show(InfoPanelType panelType)
        {
            this.uiAccountInfo.Visibility = Visibility.Collapsed;
            this.uiApplicationInfo.Visibility = Visibility.Collapsed;
            this.uiBlobInfo.Visibility = Visibility.Collapsed;
            this.uiContainerInfo.Visibility = Visibility.Collapsed;

            switch (panelType)
            {
                case InfoPanelType.Account:
                    this.uiAccountInfo.Visibility = Visibility.Visible;
                    break;
                case InfoPanelType.Application:
                    this.uiApplicationInfo.Visibility = Visibility.Visible;
                    break;
                case InfoPanelType.Blob:
                    this.uiBlobInfo.Visibility = Visibility.Visible;
                    break;
                case InfoPanelType.Container:
                    this.uiContainerInfo.Visibility = Visibility.Visible;
                    break;
                default:
                    this.uiApplicationInfo.Visibility = Visibility.Visible;
                    break;
            }
        }

        private void label1_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            MessageBox.Show("kakansdnkasd");
        }

        
       
    }
}
